using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace hao_Dto.User
{
    /// <summary>
    /// 地址信息数据传输对象
    /// </summary>
    public class AddressDto
    {
        public Guid Id { get; set; }
        public Guid UserId { get; set; }
        public string ReceiverName { get; set; }
        public string ReceiverPhone { get; set; }
        public string Province { get; set; }
        public string City { get; set; }
        public string District { get; set; }
        public string DetailAddress { get; set; }
        public string PostalCode { get; set; }
        public bool IsDefault { get; set; }
        public string AddressLabel { get; set; }
        public decimal? Longitude { get; set; }
        public decimal? Latitude { get; set; }
        public int Status { get; set; }
        public DateTime CreateTime { get; set; }
        public DateTime? UpdateTime { get; set; }
        
        /// <summary>
        /// 完整地址
        /// </summary>
        public string FullAddress => $"{Province}{City}{District}{DetailAddress}";
    }

    /// <summary>
    /// 创建地址数据传输对象
    /// </summary>
    public class CreateAddressDto
    {
        [Required(ErrorMessage = "收货人姓名不能为空")]
        [StringLength(50, ErrorMessage = "收货人姓名长度不能超过50个字符")]
        public string ReceiverName { get; set; }

        [Required(ErrorMessage = "收货人手机号不能为空")]
        [Phone(ErrorMessage = "手机号格式不正确")]
        public string ReceiverPhone { get; set; }

        [Required(ErrorMessage = "省份不能为空")]
        [StringLength(50, ErrorMessage = "省份长度不能超过50个字符")]
        public string Province { get; set; }

        [Required(ErrorMessage = "城市不能为空")]
        [StringLength(50, ErrorMessage = "城市长度不能超过50个字符")]
        public string City { get; set; }

        [Required(ErrorMessage = "区/县不能为空")]
        [StringLength(50, ErrorMessage = "区/县长度不能超过50个字符")]
        public string District { get; set; }

        [Required(ErrorMessage = "详细地址不能为空")]
        [StringLength(200, ErrorMessage = "详细地址长度不能超过200个字符")]
        public string DetailAddress { get; set; }

        [StringLength(10, ErrorMessage = "邮政编码长度不能超过10个字符")]
        public string PostalCode { get; set; }

        public bool IsDefault { get; set; }

        [StringLength(20, ErrorMessage = "地址标签长度不能超过20个字符")]
        public string AddressLabel { get; set; }

        public decimal? Longitude { get; set; }
        public decimal? Latitude { get; set; }
    }

    /// <summary>
    /// 更新地址数据传输对象
    /// </summary>
    public class UpdateAddressDto
    {
        public string ReceiverName { get; set; }
        public string ReceiverPhone { get; set; }
        public string Province { get; set; }
        public string City { get; set; }
        public string District { get; set; }
        public string DetailAddress { get; set; }
        public string PostalCode { get; set; }
        public bool? IsDefault { get; set; }
        public string AddressLabel { get; set; }
        public decimal? Longitude { get; set; }
        public decimal? Latitude { get; set; }
    }

    /// <summary>
    /// 地址搜索数据传输对象
    /// </summary>
    public class AddressSearchDto
    {
        public Guid? UserId { get; set; }
        public string Keyword { get; set; }          // 关键词搜索（收货人、手机号、地址）
        public string Province { get; set; }
        public string City { get; set; }
        public string District { get; set; }
        public bool? IsDefault { get; set; }
        public int Status { get; set; } = 1;         // 默认查询正常状态
        public int PageNumber { get; set; } = 1;
        public int PageSize { get; set; } = 10;
        public string SortBy { get; set; } = "CreateTime";
        public bool SortDesc { get; set; } = true;
    }

    /// <summary>
    /// 设置默认地址数据传输对象
    /// </summary>
    public class SetDefaultAddressDto
    {
        [Required]
        public Guid AddressId { get; set; }
    }

    /// <summary>
    /// 地址区域统计数据传输对象
    /// </summary>
    public class AddressRegionStatsDto
    {
        public string Province { get; set; }
        public string City { get; set; }
        public string District { get; set; }
        public int AddressCount { get; set; }
        public int UserCount { get; set; }
    }

    /// <summary>
    /// 省市区级联数据传输对象
    /// </summary>
    public class RegionDto
    {
        public string Code { get; set; }
        public string Name { get; set; }
        public string ParentCode { get; set; }
        public int Level { get; set; }  // 1-省，2-市，3-区
        public List<RegionDto> Children { get; set; } = new List<RegionDto>();
    }

    /// <summary>
    /// 地址导入数据传输对象
    /// </summary>
    public class ImportAddressDto
    {
        public string UserIdentifier { get; set; }   // 用户标识（用户名或手机号）
        public string ReceiverName { get; set; }
        public string ReceiverPhone { get; set; }
        public string Province { get; set; }
        public string City { get; set; }
        public string District { get; set; }
        public string DetailAddress { get; set; }
        public string PostalCode { get; set; }
        public string AddressLabel { get; set; }
        public bool IsDefault { get; set; }
    }
}